package cc.iotkit.manager.controller.adminMiniApp;

import cc.iotkit.common.api.PageRequest;
import cc.iotkit.common.api.Paging;
import cc.iotkit.common.api.Request;
import cc.iotkit.manager.dto.vo.miniAdmin.MiniAdminAreaVo;
import cc.iotkit.manager.dto.vo.miniAdmin.MiniAdminDeleteVo;
import cc.iotkit.manager.service.miniAdmin.IAreaService;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = {"后台管理小程序场地管理"})
@Slf4j
@RestController
@RequestMapping("/miniAdmin/area")
public class MiniAdminAreaController {

    @Autowired
    private IAreaService areaService;

    @Autowired
    private StringRedisTemplate redisTemplate;


    @Autowired
    private ObjectMapper objectMapper;

    @ApiOperation("新增")
    @PostMapping("/add")
    public void add( @RequestBody Request<MiniAdminAreaVo> goodsReq) throws Exception {
        MiniAdminAreaVo goodsVo =  goodsReq.getData();
        areaService.save(goodsVo);
    }

    @ApiOperation("修改")
    @PostMapping("/update")
    public void update( @RequestBody Request<MiniAdminAreaVo> goodsReq) throws Exception {
        MiniAdminAreaVo goodsVo =  goodsReq.getData();
        areaService.update(goodsVo);
    }

    @ApiOperation("分页展示")
    @PostMapping("/getPageList")
    public Paging<MiniAdminAreaVo> getPageList(@RequestBody PageRequest<MiniAdminAreaVo> request) {
        return areaService.getPageList(request);
    }

    @ApiOperation("删除")
    @PostMapping(value = "/delete")
    public void delete(@RequestBody MiniAdminDeleteVo vo) {
        areaService.delete(vo.getId());
    }
}
